package vote.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;
import vote.domain.PageParam;
import vote.domain.ResponseDTO;
import vote.domain.dto.VoteReq;
import vote.domain.vo.VoteContentResp;
import vote.service.VoteContentService;
import vote.service.VoteService;
import vote.util.SmartRequestUtil;

/**
 * Description:投票控制器
 * Author:han
 * Date: 2024-05-21
 */
@RestController
@RequestMapping("/vote")
public class voteController {
    @Resource
    private VoteService voteService;
    @Resource
    private VoteContentService voteContentService;

    //获取投票项
    @PostMapping("/getContentList")
    public ResponseDTO<IPage<VoteContentResp>> getVote(@RequestBody PageParam pageParam) {
        Long userId = SmartRequestUtil.getRequestUserId();
        return ResponseDTO.ok(voteContentService.getVoteContent(userId, pageParam));
    }

    //投票
    @PutMapping("/vote")
    public ResponseDTO<Boolean> vote(@RequestBody VoteReq voteReq) {
        return ResponseDTO.ok(voteService.vote(voteReq));
    }
}
